package com.example.flow.dao.impl;

import com.example.flow.dao.FlowTaskDao;
import com.example.flow.dao.mapper.FlowTaskMapper;
import com.example.flow.dao.model.FlowTask;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

/**
 * @author tangaq
 * 2023/6/15
 */
@Repository
public class RdsFlowTaskDaoImpl implements FlowTaskDao {
    private final FlowTaskMapper flowTaskMapper;

    public RdsFlowTaskDaoImpl(FlowTaskMapper flowTaskMapper) {
        this.flowTaskMapper = flowTaskMapper;
    }

    @Override
    public FlowTask findByTaskId(String taskId) {
        if (StringUtils.isBlank(taskId)) {
            return null;
        }
        FlowTask task = new FlowTask();
        task.setTaskId(taskId);
        return flowTaskMapper.selectOne(task);
    }

    @Override
    public void deleteTask(String taskId) {
        if (StringUtils.isBlank(taskId)) {
            return;
        }
        FlowTask task = new FlowTask();
        task.setTaskId(taskId);
        flowTaskMapper.delete(task);
    }

    @Override
    public FlowTask findByOrderId(String orderId) {
        if (StringUtils.isBlank(orderId)) {
            return null;
        }
        FlowTask task = new FlowTask();
        task.setOrderId(orderId);
        return flowTaskMapper.selectOne(task);
    }

    @Override
    public void deleteByOrderId(String orderId) {
        if (StringUtils.isBlank(orderId)) {
            return;
        }
        FlowTask task = new FlowTask();
        task.setOrderId(orderId);
        flowTaskMapper.delete(task);
    }

    @Override
    public void insert(FlowTask task) {
        flowTaskMapper.insert(task);
    }
}
